package org.example.springboot.controller;

import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.springboot.common.annotation.Loggable;
import org.example.springboot.common.page.PageResult;
import org.example.springboot.common.utils.Result;
import org.example.springboot.convert.IrrigationLogConvert;
import org.example.springboot.query.IrrigationLogQuery;
import org.example.springboot.service.IrrigationLogService;
import org.example.springboot.vo.IrrigationLogVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 灌溉日志
 *
 * @author Fz
 * @since 1.0.0 2024-08-02
 */
@Slf4j
@RestController
@RequestMapping("/irrigation-log")
@AllArgsConstructor
public class IrrigationLogController {

    private final IrrigationLogService irrigationLogService;

    @PostMapping("page")
    public Result<PageResult<IrrigationLogVO>> page(@RequestBody IrrigationLogQuery query) {
        PageResult<IrrigationLogVO> page = irrigationLogService.page(query);
        return Result.ok(page);
    }


    @PostMapping("/addedLogs")
    public Result<PageResult<IrrigationLogVO>> addedLogs(@RequestBody @Validated IrrigationLogVO vo) {
        irrigationLogService.save(IrrigationLogConvert.INSTANCE.convert(vo));
        return Result.ok();
    }

    @PostMapping("/delete")
    @Operation(summary = "删除")
    @Loggable(description = "报警清除")
    public Result<String> delete(@RequestBody List<String> ids) {
        irrigationLogService.delete(ids);
        return Result.ok();
    }

}